<?php
include_once 'ns_include.php';

class command
{
    public static $NS_PROTOCOL_PREFIX = "NS_";
    public static $NS_PROTOCOL = "NS_PROTOCOL";
    private $post = null;
    private $protocol;
    private $data;
    private $result;    
    
    public function __construct($post)
    {
        logger::called();

        $this->post = $post;   
        $this->get_protocol();
        $this->get_data();

        logger::variable($this->data);

    }
    
    public function __destruct()
    {
        
    }
    
    private function get_protocol()
    {
        logger::called();
        $this->protocol = $this->post[self::$NS_PROTOCOL];
    }
    
    private function get_data()
    {
        logger::called();
        foreach ($this->post as $key=>$value)
        {
            if (substr($key, 0, strlen(self::$NS_PROTOCOL_PREFIX)) == self::$NS_PROTOCOL_PREFIX)
            {
                $this->data[str_replace(self::$NS_PROTOCOL_PREFIX, '', $key)] = $value;
            }
        }
        $this->protocol = $this->post[self::$NS_PROTOCOL];



    }    

    public function Protocol()
    {
        return $this->protocol;
    }    

    public function Data()
    {
        return $this->data;
    }
    
    public function HasDataKey($key)
    {
        return array_key_exists($key, $this->Data());
    }

    public function GetData($key)
    {
        if (!array_key_exists($key, $this->Data())) return null;
        return $this->data[$key];
    }  
    
    public function SetResult($value)
    {
        $this->result = $value;
    }
    
    public function GetResult()
    {
        return $this->result;
    }   


    public function __toString()
    {
       return "protocol {$this->protocol} == ".print_r($this->data,true);

    }

}

?>